﻿
Imports std
Imports centrosphere

Partial Public Class storageJobDistributor
    Protected Shared Function vs_intersect_aggregate(ByVal targetJobs() As indexedJob,
                                                     ByVal inputJob As ijob) As Boolean
        aggregate_internal.assert_input(targetJobs, inputJob)
        Dim s As [set](Of String) = Nothing
        s = New [set](Of String)()
        Dim sj As storageJob = Nothing
        sj = storageJob(inputJob)
        sj.vs = New bytesVector(Of String, bytesString)()
        For i As Int64 = 0 To targetJobs.Length() - 1
            If targetJobs(i).finished() Then
                Dim tj As storageJob = Nothing
                tj = storageJob(targetJobs(i))
                If tj.result Then
                    sj.result = True
                    Dim vs As vector(Of String) = Nothing
                    vs = tj.vs
                    assert(Not vs Is Nothing)
                    For j As Int64 = 0 To vs.size() - 1
                        If s.find(vs(j)) = s.end() Then
                            sj.vs.push_back(vs(j))
                            s.insert(vs(j))
                        End If
                    Next
                End If
            End If
        Next

        Return True
    End Function
End Class
